package com.googlecode.boliang.q09.p1;

import java.util.List;

public class AGivenSum {

	public void searchByGivenSum(int givenSum, List<Integer> intList) {
		int leftPointer = 0;
		int rightPointer = intList.size() - 1;

		while (leftPointer != rightPointer) {
			if (intList.get(leftPointer) + intList.get(rightPointer) > givenSum) {
				rightPointer--;
			} else if (intList.get(leftPointer) + intList.get(rightPointer) < givenSum) {
				leftPointer++;
			} else {
				System.out.println(intList.get(leftPointer) + "+"
						+ intList.get(rightPointer) + "=" + givenSum);
				return;
			}
		}
		System.out.println("Could not find the pair of values' sum is equal to the given number! ");
		return;
	}
}
